package com.mnemonic.views.field;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

import com.mnemonic.views.GameAudio;
import com.mnemonic.views.GamePage;

/**
 * 爆炸区域
 * 
 * @author lifeng
 * @date 2021/05/15
 */
public class ExplodeField {

    public static BufferedImage[] explodes = new BufferedImage[16];

    /**
     * 爆炸的地点
     */
    private int x, y;

    /**
     * 执行爆炸的第几步
     */
    private int step = 0;

    /**
     * 雷区的引用
     */
    private MineFields mf;

    static {
        try {
            for (int i = 0; i < 16; i++) {
                explodes[i] = ImageIO.read(GamePage.class.getResourceAsStream("e" + (i + 1) + ".gif"));
            }
        } catch (Exception e) {
        }
    }

    /**
     * 开启爆炸
     */
    public ExplodeField(MineFields mf, int x, int y) {
        this.mf = mf;
        this.x = x;
        this.y = y;
        new ExplodeAudio().start();
    }

    /**
     * 绘制爆炸的效果
     * 
     * @param g
     */
    public void paint(Graphics g) {
        g.drawImage(explodes[step++], x - 30, y - 60, null);
        if (step >= explodes.length) {
            mf.removeExplode(this);
        }
    }

    /**
     * 爆炸的音效
     * 
     * @author lifeng
     * @date 2021/05/15
     */
    public class ExplodeAudio extends GameAudio {
        public ExplodeAudio() {
            super("explode.wav");
        }
    }
}
